<template>
  <div class="site-wrapper site-page--login">
    <div class="site-content__wrapper">
      <div class="site-content">

        <div class="login-main">
          <h3 class="login-title">注册</h3>
          <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRoles" status-icon
                   @keyup.enter.native="login"
          >
            <el-form-item prop="username">
              <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="loginForm.password" placeholder="密码" type="password"></el-input>
            </el-form-item>
            <el-form-item prop="email">
              <el-input v-model="loginForm.email" placeholder="邮箱"></el-input>
            </el-form-item>
            <el-form-item prop="phone">
              <el-input v-model="loginForm.phone" placeholder="手机号"></el-input>
            </el-form-item>
            <el-form-item prop="name">
              <el-input v-model="loginForm.name" placeholder="昵称" type="password"></el-input>
            </el-form-item>
            <el-form-item prop="roleName">
              <p style="color: #ffffff;margin: 0;padding: 0">角色</p>
              <el-select v-model="loginForm.roleName" placeholder="请选择">
                <el-option
                  v-for="item in roleList"
                  :key="item.id"
                  :label="item.nameZh"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button class="login-btn-submit" type="primary" @click="login">注册</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>


  </div>

</template>

<script>

import { addUser, roleList } from '@/api/boot/api'
import RoleList from '@/components/power/RoleList.vue'

export default {
  computed: {
    RoleList() {
      return RoleList
    }
  },
  data() {
    return {
      //这是注册表单的数据绑定对象
      loginForm: {
        username: '',
        password: '',
        code: '',
        rememberMe: false
      },

      //这是表单的验证规则对象
      loginFormRoles: {
        //验证用户名是否合法
        username: [
          { required: true, message: '请输入注册名称', trigger: 'blur' },
          { min: 3, max: 12, message: '长度在3到10个字符', trigger: 'blur' }
        ],
        //验证密码是否合法
        password: [
          { required: true, message: '请输入注册密码', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在3到15个字符', trigger: 'blur' }
        ]
      },
      roleList: [],
      smsLoginRules: {
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { min: 11, max: 12, message: '格式错误' }
        ]
      }
    }
  },
  created() {
    roleList().then((res) => {
      this.roleList = res.obj
      console.log(this.roleList, 'roleList')
      this.loading = false
    })
  },

  methods: {
    login() {
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return

        addUser(this.loginForm).then((res) => {
          if (res.status == 200) {
            this.msgSuccess(res.msg)
            this.$router.push({ path: '/', replace: true })
          } else {
            this.msgError(res.msg)
          }

        })

      })
    }
  }
}
</script>
<!--scoped如果加上只在本页面生效，去掉就全局生效,只要是但文件就定义-->
<style lang="less" scoped>
.el-form-item__label {
  color: #ffffff !important;
}

.site-wrapper.site-page--login {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(38, 50, 56, .6);
  overflow: hidden;

  &:before {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    content: "";
    background-image: url(~@/assets/img/login_bg.jpg);
    background-size: cover;
  }

  .site-content__wrapper {

    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    background-color: transparent;
  }

  .site-content {
    min-height: 100%;
    padding: 30px 500px 30px 30px;
  }

  .brand-info {
    margin: 220px 100px 0 90px;
    color: #fff;
  }

  .brand-info__text {
    margin: 0 0 22px 0;
    font-size: 48px;
    font-weight: 400;
    text-transform: uppercase;
  }

  .brand-info__intro {
    margin: 10px 0;
    font-size: 16px;
    line-height: 1.58;
    opacity: .6;
  }

  .login-main {
    position: absolute;
    top: 10%;
    right: 40%;
    //padding: 150px 60px 180px;
    width: 20%;
    min-height: 100%;
    background-color: Transparent;
  }

  .login-title {
    font-size: 25px;
    color: #fff;
  }

  .login-captcha {
    overflow: hidden;

    > img {
      width: 100%;
      cursor: pointer;
    }
  }

  .login-btn-submit {
    width: 100%;
    margin-top: 18px;
  }

}

</style>
